package com.example.springprinciple;

import org.springframework.context.ApplicationContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CatController {
    @Autowired
    private Cat singleCat;
    @Autowired
    private Cat prototypeCat;
    @Autowired
    private Cat requestCat;
    @Autowired
    private Cat sessionCat;
    @Autowired
    private Cat applicationCat;
    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping("/single")
    public String single(){
        Cat contextCat = (Cat)applicationContext.getBean("singleCat");
        return "cat:"+singleCat.toString()+",contextCat:"+contextCat;
    }
    @RequestMapping("/prototype")
    public String prototype(){
        Cat contextCat = (Cat)applicationContext.getBean("prototypeCat");
        return "cat:"+prototypeCat.toString()+",contextCat:"+contextCat;
    }
    @RequestMapping("/request")
    public String request(){
        Cat contextCat = (Cat)applicationContext.getBean("requestCat");
        return "cat:"+requestCat.toString()+",contextCat:"+contextCat;
    }
    @RequestMapping("/session")
    public String session(){
        Cat contextCat = (Cat)applicationContext.getBean("sessionCat");
        return "cat:"+sessionCat.toString()+",contextCat:"+contextCat;
    }
    @RequestMapping("/application")
    public String application(){
        Cat contextCat = (Cat)applicationContext.getBean("applicationCat");
        return "cat:"+applicationCat.toString()+",contextCat:"+contextCat;
    }
}
